package com.cy.pj.sys.web.controller;

import com.cy.pj.common.pojo.JsonResult;
import com.cy.pj.common.util.PageUtil;
import com.cy.pj.sys.pojo.SysLog;
import com.cy.pj.sys.service.SysLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

//restful 风格url(一种编码风格)
//@GetMapping 所有-->/log/
//@GetMapping 某个-->/log/{id}
//@DeleteMapping 某些-->/log/{id}
@RequestMapping("/log/")
@CrossOrigin
@RestController
public class SysLogController
{
    @Autowired
    private SysLogService sysLogService;

    @DeleteMapping("{ids}")
    public JsonResult doDeleteById(@PathVariable Long... ids)
    {
        sysLogService.deleteById(ids);
        return new JsonResult("delete ok");
    }

    @GetMapping("{id}")
    public JsonResult doFindById(@PathVariable Long id)
    {
        return new JsonResult(sysLogService.findById(id));
    }

    @GetMapping
    public JsonResult doFindLogs(SysLog sysLog)
    {
        return new JsonResult(PageUtil.startPage()
                .doSelectPageInfo(() -> sysLogService.findLogs(sysLog)));
        /*return new JsonResult(PageUtil.startPage().doSelectPageInfo(new ISelect()
        {
            @Override
            public void doSelect()
            {
                sysLogService.findLogs(sysLog);
            }
        }));*/
        //return new JsonResult(sysLogService.findLogs(sysLog));
    }
}
